package com.ifast.integral.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ifast.common.utils.Result;
import com.ifast.integral.dao.IntegralConfigDao;
import com.ifast.integral.domain.IntegralConfig;
import com.ifast.integral.service.IntegralConfigService;


/**
 * 
 * @author ShiQiang
 * @date 2019年4月9日09:56:53
 */
@Transactional
@Service("integralConfigService")
public class IntegralConfigServiceImpl extends ServiceImpl<IntegralConfigDao, IntegralConfig> implements IntegralConfigService{

	@Override
	public Result<?> save(IntegralConfig integral) {
		//这个需要设计一下。后期添加字段了会需要变更
		integral.setOpen(isNull(integral.getOpen()))
				.setFormalMax(isNull(integral.getFormalMax()))
				.setFormalMin(isNull(integral.getFormalMin()))
				.setFormalR(isNull(integral.getFormalR()))
				.setLearnMax(isNull(integral.getLearnMax()))
				.setLearnMin(isNull(integral.getLearnMin()))
				.setLearnTime(isNull(integral.getLearnTime()))
				.setLoginMax(isNull(integral.getLoginMax()))
				.setLoginMin(isNull(integral.getLoginMin()))
				.setOneDayMax(isNull(integral.getOneDayMax()))
				.setOneDayMin(isNull(integral.getOneDayMin()))
				.setOneDayR(isNull(integral.getOneDayR()))
				.setOneWeekMax(isNull(integral.getOneWeekMax()))
				.setOneWeekMin(isNull(integral.getOneWeekMin()))
				.setOneWeekR(isNull(integral.getOneWeekR()))
				.setPhotoMax(isNull(integral.getPhotoMax()))
				.setPhotoMin(isNull(integral.getPhotoMin()))
				.setReadMax(isNull(integral.getReadMax()))
				.setReadMin(isNull(integral.getReadMin()))
				.setReadTime(isNull(integral.getReadTime()))
				.setShareMax(isNull(integral.getShareMax()))
				.setShareMin(isNull(integral.getShareMin()))
				.setSmartMax(isNull(integral.getSmartMax()))
				.setSmartMin(isNull(integral.getSmartMin()))
				.setSmartR(isNull(integral.getSmartR()));
		return this.selectCount(new EntityWrapper<IntegralConfig>(IntegralConfig
				.builder().dwCode(integral.getDwCode()).build())) > 0 ?
    		(this.updateById(integral)? Result.ok() : Result.fail()):
	    	(this.insert(integral) ? Result.ok() : Result.fail()); 
	}
	private Integer isNull(Integer src){
		return src == null ? 0 : src;
	}
}